/*
    $Header: /Windows/Shell/ShellExt.root/ShellExt/src/CCpHook.h 1     08-01-05 0:08 Ken $
    $Log: /Windows/Shell/ShellExt.root/ShellExt/src/CCpHook.h $
 * 
 * 1     08-01-05 0:08 Ken
*/


#pragma once
#include "resource.h"       // main symbols

#include "ShellExt.h"


// CCpHook

class ATL_NO_VTABLE CCpHook :
    public CComObjectRootEx<CComSingleThreadModel>,
    public CComCoClass<CCpHook, &CLSID_CpHook>,
    public ICopyHook,    //3 ken !!!Note: to use COM_INTERFACE_ENTRY_IID, this public ICopyHook MUST NOT be the last base class
    public IDispatchImpl<ICpHook, &IID_ICpHook, &LIBID_ShellExtLib, /*wMajor =*/ 1, /*wMinor =*/ 0>
{
private:
	enum EN_CPHK_DOSELENCE_CAUSE
	{
		CPHK_DOSILENCE_CAUSE_PATH=0,
		CPHK_DOSILENCE_CAUSE_CREATE,
		CPHK_DOSILENCE_CAUSE_DEL
	};
public:
    CCpHook()
    :m_hwnd(NULL)
    {
    }

DECLARE_REGISTRY_RESOURCEID(IDR_CPHOOK)


BEGIN_COM_MAP(CCpHook)
    COM_INTERFACE_ENTRY(ICpHook)
    //3 system not define ICopyHook.
    //3 so use macro COM_INTERFACE_ENTRY_IID, NOTE: this interface ICopyHook MUST NOT be the last base class ;
    //3 or add this defines "struct __declspec(uuid("xxx-xx-xx-x-xx")) ICopyHook;", but how to find the "xxx-xx-xx-x-xx"? */
    //    COM_INTERFACE_ENTRY(ICopyHook)
    COM_INTERFACE_ENTRY_IID(IID_IShellCopyHook, CCpHook)
    COM_INTERFACE_ENTRY(IDispatch)
END_COM_MAP()


    DECLARE_PROTECT_FINAL_CONSTRUCT()

    HRESULT FinalConstruct()
    {
        return S_OK;
    }

    void FinalRelease()
    {
    }

// IShellCopyHook
public:
    STDMETHOD_(UINT, CopyCallback)( HWND hwnd,UINT wFunc, UINT wFlags, LPCTSTR pszSrcFile, DWORD dwSrcAttribs, LPCTSTR pszDestFile, DWORD dwDestAttribs);

private:
    UINT DoFO_COPY(LPCTSTR pszJunctTgt, LPCTSTR pszDestFile, HWND hwnd);
    UINT DoFO_DELETE(LPCTSTR pszJunctName, HWND hwnd);

private:
    // use the hwnd to identify a copy session
    // return IDYES IDNO  IDCANCEL or 0
    UINT DoSilenceOpt(EN_CPHK_DOSELENCE_CAUSE enCause, HWND hwnd);

private:
    int m_enDoSilence[3];
    HWND m_hwnd;    // selience ignore window
};

OBJECT_ENTRY_AUTO(__uuidof(CpHook), CCpHook)
